#!/bin/bash -e

# This script uses inotifywait(1) to copy a file whenever it changes.
# The file is copied to $HOME/Nextcloud/ and a line is appended to a
# logfile.
#
# The script is started from $HOME/.config/autostart/syncer.desktop
# The contents of $HOME/Nextcloud/ is automatically synced by another
# program with a nextcloud installation somewhere remote. This way a
# recent version of the file is always available to other devices
# (notably my smartphone).

FILE="$HOME/somefile"
echo "$(date)   started $0" >> $0.log
cat $0 >> $0.log

while true ; do

   inotifywait -q -e modify $FILE
   echo "$(date) uploading modified $FILE" >> $0.log
   cp $FILE $HOME/Nextcloud/

done
